﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace JJY.CommonHelper
{
    public static class JJYExtension
    {
        public static string ToUTF8(this string str)
        {
            string result = string.Empty;
            byte[] byteString = Encoding.GetEncoding("gb2312").GetBytes(str);
            byte[] byteResult = Encoding.Convert(Encoding.GetEncoding("gb2312"), Encoding.UTF8, byteString);

            char[] charSet = new char[Encoding.UTF8.GetCharCount(byteResult, 0, byteResult.Length)];
            Encoding.UTF8.GetChars(byteResult, 0, byteResult.Length, charSet, 0);
            result = new string(charSet);

            return result;
        }

        public static string HtmlToString(this string str)
        {
            string EmptyString = string.Empty;
            return str.Replace("\t", EmptyString).Replace("\r", EmptyString).Replace("\n", EmptyString)
                .Replace("&nbsp;", EmptyString).Replace("　", EmptyString);
        }

        public static Guid ToGuid(this string str)
        {
            Guid result = Guid.Empty;
            try
            {
                Guid.TryParse(str, out result);
            }
            catch
            {
 
            }
            return result;
        }

        public static string ReplaceEmpty(this string str)
        {
            return str.Replace(" ",string.Empty);
        }
    }
}
